﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CSC.FSVTracker.Domain.Abstract;
using CSC.FSVTracker.WebUI.Models;
using CSC.FSVTracker.WebUI.Helper;
using CSC.FSVTracker.Domain.Entities;

namespace CSC.FSVTracker.WebUI.Controllers
{
    public class UserController : BaseController
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="HomeController"/> class.
        /// </summary>
        /// <param name="repository">The repository.</param>
        public UserController(IUserRepository repository) : base(repository) { }

        [HttpGet]
        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Add(UserViewModel userViewModel)
        {
            if (ModelState.IsValid)
            {
                User newUser = new User
                {
                    LoginId = userViewModel.LoginId,
                    Name = userViewModel.Name,
                    Password = userViewModel.Password,
                    EmailId = userViewModel.EmailId,
                    Role = "User",
                    UserGroup = userViewModel.UserGroup
                };
                userRepository.SaveUser(newUser);
            }
            return RedirectToAction("Index", "Home");
        }
    }
}
